// gray.frag.js
module.exports =
`
// Author @patriciogv ( patriciogonzalezvivo.com ) - 2015

#ifdef GL_ES
precision mediump float;
#endif

varying vec4 v_fragmentColor; 
varying vec2 v_texCoord; 

uniform float u_time;

#define PI 3.14159265358979323846
#define W 750.0
#define H 1335.0

vec2 rotate2D(vec2 _st, float _angle){
    _st -= 0.5;
    _st =  mat2(cos(_angle),-sin(_angle),
                sin(_angle),cos(_angle)) * _st;
    _st += 0.5;
    return _st;
}

vec2 tile(vec2 _st, float _zoom){
    _st *= _zoom;
    _st.y *=  H/W;
    return fract(_st);
}

float box(vec2 _st, vec2 _size, float _smoothEdges){
    _size = vec2(0.5)-_size*0.5;
    vec2 aa = vec2(_smoothEdges*0.5);
    vec2 uv = smoothstep(_size,_size+aa,_st);
    uv *= smoothstep(_size,_size+aa,vec2(1.0)-_st);
    return uv.x*uv.y;
}

vec2 movingTiles(vec2 _st, float _speed){
    float time = u_time *_speed;
    _st.x += fract(time)*2.0;    
    _st.y += fract(time)*2.0;  
    return fract(_st);
}

void main(void){
    vec2 st = v_texCoord;
    vec3 color = vec3(0.955,0.684,0.447);

    // Divide the space in 4
    st = tile(st,5.000);

    st = movingTiles(st, 3.0);
    
    // Use a matrix to rotate the space 45 degrees
    st = rotate2D(st,PI*0.25);

    float fact = box(st,vec2(0.72,0.72), 0.05);
    // Draw a square
    color =   (1.0 - fact) * vec3(0.99, 0.8,0.54) + fact * vec3(0.99,0.54,0.13);
    // color = vec3(st,0.0);

    gl_FragColor = vec4(color,1.0);
}

`